package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 运营数据统计操作
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService{

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;


    //统计运营数据
    public Map<String, Object> getBusinessReportData() throws Exception {
        //创建运营数据封装map
        Map<String, Object> data = new HashMap<>();

        //动态获取今天日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //动态获取本周一的日期
        String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //动态获取本月1号
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());



        //今日新增会员数量
        Integer todayNewMember = memberDao.findMemberCountByDate(today);

        //总会员数量
        Integer totalMember = memberDao.findMemberTotalCount();

        //本周新增会员数量
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);

        //本月新增会员数量
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);

        //今日预约订单数量
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);

        //今日到诊数量
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);

        //本周预约订单数量
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(monday);

        //本周到诊数量
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(monday);

        //本月预约订单数量
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);

        //本月到诊数量
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

        data.put("reportDate", today);
        data.put("todayNewMember", todayNewMember);
        data.put("totalMember", totalMember);
        data.put("thisWeekNewMember", thisWeekNewMember);
        data.put("thisMonthNewMember", thisMonthNewMember);
        data.put("todayOrderNumber", todayOrderNumber);
        data.put("todayVisitsNumber", todayVisitsNumber);
        data.put("thisWeekOrderNumber", thisWeekOrderNumber);
        data.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
        data.put("thisMonthOrderNumber", thisMonthOrderNumber);
        data.put("thisMonthVisitsNumber", thisMonthVisitsNumber);

        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        data.put("hotSetmeal", hotSetmeal);


        return data;
    }
}
